package com.xzkydz.sensor.sensor;


import com.xzkydz.sensor.sensor.base.BaseSensorData;
import com.xzkydz.sensor.utils.CalculationUtils;
import com.xzkydz.sensor.utils.RandomUtils;

/**
 * 压力传感器数据解析
 */
public class YaLiBean extends BaseSensorData {

    /**
     * 压力数据
     */
    public Float[] yaLiArray = new Float[5];
    /**
     * 平均压力
     */
    public float yaLiAver = 0F;

    @Override
    protected void calculate(byte[] recData) {
        super.calculate(recData);
        float fraction = 1f;
        switch (sensorTypeVel) {
            case "20": //0x20
            case "21": //0x21
            case "23": //0x23
                fraction = 1000f;
                break;
            case "24": //0x24
                fraction = 10000f;
                break;
            case "27": //0x27
                fraction = 10f;
                break;
        }

        int symbol0 = bRec[14];
        int symbol1 = bRec[17];
        int symbol2 = bRec[20];
        int symbol3 = bRec[23];
        int symbol4 = bRec[26];

        yaLiArray[0] = CalculationUtils.twoByteToIntNoSign(bRec[15], bRec[16]) / fraction;
        yaLiArray[1] = CalculationUtils.twoByteToIntNoSign(bRec[18], bRec[19]) / fraction;
        yaLiArray[2] = CalculationUtils.twoByteToIntNoSign(bRec[21], bRec[22]) / fraction;
        yaLiArray[3] = CalculationUtils.twoByteToIntNoSign(bRec[24], bRec[25]) / fraction;
        yaLiArray[4] = CalculationUtils.twoByteToIntNoSign(bRec[27], bRec[28]) / fraction;

        if (symbol0 == 1) yaLiArray[0] = 0 - yaLiArray[0];
        if (symbol1 == 1) yaLiArray[1] = 0 - yaLiArray[1];
        if (symbol2 == 1) yaLiArray[2] = 0 - yaLiArray[2];
        if (symbol3 == 1) yaLiArray[3] = 0 - yaLiArray[3];
        if (symbol4 == 1) yaLiArray[4] = 0 - yaLiArray[4];

        yaLiAver = (yaLiArray[0] + yaLiArray[1] + yaLiArray[2] + yaLiArray[3] + yaLiArray[4]) / 5f;
    }

    @Override
    protected void simulation(int sensorNum) {
        super.simulation(sensorNum);
        yaLiAver = RandomUtils.getInstance().randomFloat(20f);
        for (int i = 0; i < yaLiArray.length ; i++) {
            yaLiArray[i] = RandomUtils.getInstance().randomFloat(20f);
        }
    }
}
